export default {
  data() {
    return {
      loginForm: {
        username: 'admin',
        password: '123456'
      },
      loginFormRules: {
        username: [{ required: true, message: '请填写用户名', trigger: 'blur' }],
        password: [{ required: true, message: '请填写用户密码', trigger: 'blur' }]
      }
    }
  },
  methods: {
    submitForm() {
      this.$refs.ruleFormRef.validate(async valid => {
        if (!valid) return false
        // 发送ajax
        const { data: res } = await this.$http.post('login', {
          username: this.loginForm.username,
          password: this.loginForm.password
        })
        console.log(res)
        if (res.meta.status !== 200) return this.$message.error('登录失败')
        window.sessionStorage.setItem('token', res.data.token)
        this.$message.success('登录成功')
        this.$router.push('/home')
      })
    },
    resetForm() {
      this.$refs.ruleFormRef.resetFields()
    }
  }
}
